package entity;

import java.util.ArrayList;
import java.util.List;


// 针对所有用户的数据模型，涵盖当前用户、联系人及陌生校友
public class User {

    private static final float INVALID_LAT_LNG_DISTINGUISHER = -180.0F;

    //当前用户
    public static final int USER_TYPE_ME = 0;
    //联系人
    public static final int USER_TYPE_CONTACT = 1;
    //校友
    public static final int USER_TYPE_SCHOOLMATE = 2;


    private Long id;

//    @NotNull
//    @Property(nameInDb = "dc_userid")
//    private Long userId;

    private String username = "";    //用户名，登录名称，昵称

    private String userPhone = "";    //用户手机号

    private String userStuId = "";    //学号

//    @NotNull
//    @Property(nameInDb = "dc_user_introduction")
//    private String userIntroduction = "";    //学院专业那一届描述

    private String name = "";        //真实姓名

    private String pinyinName;       //拼音

    private String iconUri = "";      //头像

    private String bgImgUri = "";     //背景色

    private String city = "";         //当前所在城市

    private String specialtyStr = "";   //爱好，特长

    private String selfIntroduction = "";  //自我介绍

    private double lng = Double.MIN_VALUE;

    private double lat = Double.MIN_VALUE;

    private long lastRefreshTime = 0;

    private int type = User.USER_TYPE_ME;   //用户类型

    private int isDelete = 0;

    private List<String> specialtyList = new ArrayList<String>();

    /*以下代码由greenDAO生成*/






    public User(Long id, String username, String userPhone,
            String userStuId, String name,
            String pinyinName,  String iconUri,
           String bgImgUri,  String city,
            String specialtyStr, String selfIntroduction,
            double lng, double lat, long lastRefreshTime, int type, int isDelete) {
        this.id = id;
        this.username = username;
        this.userPhone = userPhone;
        this.userStuId = userStuId;
        this.name = name;
        this.pinyinName = pinyinName;
        this.iconUri = iconUri;
        this.bgImgUri = bgImgUri;
        this.city = city;
        this.specialtyStr = specialtyStr;
        this.selfIntroduction = selfIntroduction;
        this.lng = lng;
        this.lat = lat;
        this.lastRefreshTime = lastRefreshTime;
        this.type = type;
        this.isDelete = isDelete;
    }


    public User() {
    }



    /* 其它自定义方法 */
    public boolean hasLocation() {
        return (this.lng >= INVALID_LAT_LNG_DISTINGUISHER) &&
                (this.lat >= INVALID_LAT_LNG_DISTINGUISHER);
    }

    public void setLocation(long lng, long lat) {
        this.lng = lng;
        this.lat = lat;
        this.lastRefreshTime = System.currentTimeMillis();
    }

    public boolean hasSelfIntroduction() {
        return this.selfIntroduction.length() > 0;
    }

    public void copy(User u) {
        this.username = u.username;
        this.name = u.name;
        this.userPhone = u.userPhone;
        //this.userIntroduction = u.userIntroduction;
        this.userStuId = u.userStuId;
        this.pinyinName = u.pinyinName;
        this.iconUri = u.iconUri;
        this.bgImgUri = u.bgImgUri;
        this.city = u.city;
        this.specialtyStr = u.specialtyStr;
        this.selfIntroduction = u.selfIntroduction;
        this.lng = u.lng;
        this.lat = u.lat;
        this.lastRefreshTime = u.lastRefreshTime;
        this.type = u.type;
        this.isDelete = u.isDelete;
    }

    public int getIsDelete() {
        return isDelete;
    }

    public void setIsDelete(int isDelete) {
        this.isDelete = isDelete;
    }

    public Long getId() {
        return this.id;
    }


    public void setId(Long id) {
        this.id = id;
    }


    public String getUsername() {
        return this.username;
    }


    public void setUsername(String username) {
        this.username = username;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserStuId(String userStuId) {
        this.userStuId = userStuId;
    }

    public String getUserStuId() {
        return userStuId;
    }

    public String getName() {
        return this.name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public String getPinyinName() {
        return this.pinyinName;
    }


    public void setPinyinName(String pinyinName) {
        this.pinyinName = pinyinName;
    }


    public String getIconUri() {
        return this.iconUri;
    }


    public void setIconUri(String iconUri) {
        this.iconUri = iconUri;
    }


    public String getBgImgUri() {
        return this.bgImgUri;
    }


    public void setBgImgUri(String bgImgUri) {
        this.bgImgUri = bgImgUri;
    }


    public String getCity() {
        return this.city;
    }


    void setCity(String city) {
        this.city = city;
    }


    public String getSpecialtyStr() {
        return this.specialtyStr;
    }


    public void setSpecialtyStr(String specialtyStr) {
        this.specialtyStr = specialtyStr;
    }


    public String getSelfIntroduction() {
        return this.selfIntroduction;
    }


    public void setSelfIntroduction(String selfIntroduction) {
        this.selfIntroduction = selfIntroduction;
    }


    public double getLng() {
        return this.lng;
    }


    public void setLng(double lng) {
        this.lng = lng;
    }


    public double getLat() {
        return this.lat;
    }


    public void setLat(double lat) {
        this.lat = lat;
    }


    long getLastRefreshTime() {
        return this.lastRefreshTime;
    }


    public void setLastRefreshTime(long lastRefreshTime) {
        this.lastRefreshTime = lastRefreshTime;
    }


    public int getType() {
        return this.type;
    }


    public void setType(int type) {
        this.type = type;
    }


    public boolean isContact() {
        return type == User.USER_TYPE_CONTACT;
    }

    public String getEncryptName() {
        return name.substring(0, 1) + "* *";

    }


    public List<String> getSpecialtyList() {
        if (specialtyList.size() <= 0) {
            String[] specialities = specialtyStr.split(";");
            for (int i = 0; i < specialities.length; i++)
                specialtyList.add(specialities[i]);
        }
        return specialtyList;
    }

    public void setSpecialtyList(List<String> specialties) {
        specialtyList.clear();
        specialtyList.addAll(specialties);
        specialtyStr = "";
        for (String s : specialties)
            specialtyStr += s + ";";
        specialtyStr = specialtyStr.substring(0, specialtyStr.length() - 1);
    }

    public String getProvinceName() {
        int pos = city.indexOf(' ');
        return city.substring(0, pos);
    }

    public String getCityName() {
        int pos = city.indexOf(' ');
        return city.substring(pos + 1);
    }

    public void setCity(String provName, String cityName) {
        city = provName + " " + cityName;
    }


//    public String getUserIntroduction() {
//        return this.userIntroduction;
//    }
//
//
//    public void setUserIntroduction(String introduction) {
//        this.userIntroduction = introduction;
//    }


}
